package dominio;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

import persistencia.PersistentObject;
import dto.ClienteTO;

@Entity
@Table(name = "Cliente")
public class Cliente extends PersistentObject {
	private static final long serialVersionUID = 1L;

	@Column(name = "cuil", nullable = false, columnDefinition = "varchar(32)")
	private String cuil;

	@Column(name = "razonSocial", nullable = false, columnDefinition = "varchar(32)")
	private String razonSocial;

	@Column(name = "activo", nullable = false, columnDefinition = "bit")
	private boolean activo;

	public String getCuil() {
		return cuil;
	}

	public void setCuil(String cuil) {
		this.cuil = cuil;
	}

	public String getRazonSocial() {
		return razonSocial;
	}

	public void setRazonSocial(String razonSocial) {
		this.razonSocial = razonSocial;
	}

	public boolean isActivo() {
		return activo;
	}

	public void setActivo(boolean activo) {
		this.activo = activo;
	}

	public ClienteTO getDTO() {
		ClienteTO dto = new ClienteTO();
		dto.setId(id);
		dto.setCuil(cuil);
		dto.setRazonSocial(razonSocial);
		dto.setActivo(activo);
		return dto;
	}

	public static Cliente fromDTO(ClienteTO dto) {
		if (dto == null)
			return null;
		Cliente c = new Cliente();
		c.setId(dto.getId());
		c.setCuil(dto.getCuil());
		c.setRazonSocial(dto.getRazonSocial());
		c.setActivo(dto.isActivo());
		return c;
	}
}